package com.br.gapps.crm.controller;

import java.util.ArrayList;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.persistence.EntityManager;

import com.br.gapps.crm.entity.Customer;
import com.br.gapps.crm.repository.CustomerRepository;

@ManagedBean
@ViewScoped
public class CustomersBean {

	Customer customer = new Customer();
	
	public CustomersBean() {
		super();
	}
	public Customer getCustomer() {
		return customer;
	}
	public void setCustomer(Customer customer) {
		this.customer = customer;
	}
	public List<Customer> getCustomers() {
		CustomerRepository repository = new CustomerRepository();
		return repository.findAll();
	}
	public void addCustomer() {
	    CustomerRepository repository = new CustomerRepository();
	    repository.adiciona(getCustomer());
	    this.setCustomer(new Customer());
	}
	public void removeCustomer(Customer customer){
		CustomerRepository repository = new CustomerRepository();
	    repository.remove(customer);
	}
}
